package com.sales.service.task;

import java.io.IOException;
import java.net.URISyntaxException;

import org.apache.http.HttpEntity;
import org.apache.http.ParseException;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.util.EntityUtils;

import android.os.AsyncTask;
import android.util.Log;

import com.sales.service.http.HttpServiceHelper;
import com.sales.service.http.ServiceRequest;

public class ServiceTask extends AsyncTask<ServiceRequest, Object, Object>{

	private static final String TagProject = "SalesService";
	private static final String TagPage = "Task ::";
	
	@Override
	protected void onPreExecute() {
		// TODO Auto-generated method stub
		super.onPreExecute();
	}
	
	@Override
	protected Object doInBackground(ServiceRequest... params) {
		HttpServiceHelper helper = new HttpServiceHelper(params[0]);
		Log.i(TagProject, TagPage + params[0].getRequesturl());
		HttpEntity entity=null;
		try {
			entity = helper.execute();
		} catch (ClientProtocolException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} catch (URISyntaxException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		Log.i(TagProject, TagPage + entity);
		String s=null;
		try {
			s = EntityUtils.toString(entity);
			Log.i(TagProject, TagPage+s);
		} catch (ParseException e) {
			Log.i(TagProject, TagPage + e.getMessage() + ", " + e.getCause() + ", " + e.getClass());
			e.printStackTrace();
		} catch (IOException e) {
			Log.i(TagProject, TagPage + e.getMessage() + ", " + e.getCause() + ", " + e.getClass());
			e.printStackTrace();
		}
		return s;
	}
	
	@Override
	protected void onProgressUpdate(Object... values) {
		// TODO Auto-generated method stub
		super.onProgressUpdate(values);
	}
	
	@Override
	protected void onPostExecute(Object result) {
		// TODO Auto-generated method stub
		super.onPostExecute(result);
	}

}